/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 * Description: 新算子tiling的头文件
 * Author: qingjicheng
 * Create: 2021-4-27
 */

#ifndef OPS_BUILT_IN_OP_TILING_ELETWISE_H
#define OPS_BUILT_IN_OP_TILING_ELETWISE_H

#include <vector>
#include <string>

#include <nlohmann/json.hpp>
#include "op_tiling.h"
namespace TbeReduce {
/* int8类型的算子与其他算子开发时间不同，与老的tiling逻辑不匹配，该类提供了新的tiling逻辑 */
class EletwiseV2 {
public:
static const int64_t ELEWISE_REPEATE_NUMS = 128;
static const int64_t ELEWISE_UINT1_REPEATE_NUMS = 256;
static const int64_t DOUBLE_BUFFER_SIZE = 2;

public:
    explicit EletwiseV2(const std::string& opType, const TbeReduce::TeOpParas& opParas,
                          const nlohmann::json& opInfo, const std::vector<bool>& flagInfo)
        : opType_(opType), opParas_(opParas), opInfo_(opInfo), flagInfo_(flagInfo)
    {
    }
        ~EletwiseV2()
    {
    }
    bool WriteTilingData(TbeReduce::OpRunInfo& runInfo) const;
    bool DoTiling();

private:
    bool Init();
    bool GenerateOutputShape();
    bool CalcTiling();
    bool DoBlockTiling();
    bool DoUbTiling();
    void CalcKey();

private:
    const std::string& opType_;
    const TbeReduce::TeOpParas& opParas_;
    const nlohmann::json& opInfo_;
    const std::vector<bool>& flagInfo_;
    std::vector<int64_t> outputShape_{};
    int64_t key_{-1};
    int64_t maxAvailableUb_{0};
    int64_t maxAvailableUbDb_{0};
    int64_t blockAxis_{-1};
    int64_t ubAxis_{-1};
    int64_t blockDims_{1};
    int64_t ubFactor_{1};
    int64_t blockFactor_{1};
    int64_t maxDtype_{0};
    int64_t coreNum_{0};
    std::string inType_;
    std::string outType_;
    bool onlyConstTiling_{false};
    bool useSpecialPattern_{false};
    bool needMultiCore_{true};
    bool needDoubleBuffer_{false};
};
}  // namespace TbeReduce
#endif  // OPS_BUILT_IN_OP_TILING_ELETWISE_H